//
//  ConversationlistViewController.swift
//  微信Swift
//
//  Created by ztDev on 15/10/7.
//  Copyright © 2015年 CC. All rights reserved.
//

import UIKit

class ConversationlistViewController: RCConversationListViewController {

    
    // PopMenu效果弹出菜单
    @IBAction func showMenu(sender: UIBarButtonItem) {
        
        let items = [
            
            MenuItem(title: "与陈超聊天", iconName: "contact", glowColor: UIColor.blueColor(), index: 0),
        ]
        
        let menu = PopMenu(frame: self.view.bounds, items: items)
        
        menu.menuAnimationType = .NetEase
        
        if menu.isShowed {
            return
        }
        
        menu.didSelectedItemCompletion = { (selectedItem: MenuItem!) -> Void in
            
            switch selectedItem.index {
                
            case 0:
                //代码跳转到会话界面
                let conVC = RCConversationViewController()
                
                conVC.targetId = "chenchao"
                conVC.userName = "陈超"
                conVC.conversationType = RCConversationType.ConversationType_PRIVATE
                
                conVC.title = conVC.userName
                
                self.navigationController?.pushViewController(conVC, animated: true)
                
                self.tabBarController?.tabBar.hidden = true
                
            default :
//                print(selectedItem.title)
                return
            }
            
        }
        
        menu.showMenuAtView(self.view)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
        appDelegate?.connectSever({ () -> Void in
            
            self.setDisplayConversationTypes ([
                
                RCConversationType.ConversationType_APPSERVICE.rawValue,
                RCConversationType.ConversationType_CHATROOM.rawValue,
                RCConversationType.ConversationType_CUSTOMERSERVICE.rawValue,
                RCConversationType.ConversationType_DISCUSSION.rawValue,
                RCConversationType.ConversationType_GROUP.rawValue,
                RCConversationType.ConversationType_PRIVATE.rawValue,
                RCConversationType.ConversationType_PUBLICSERVICE.rawValue,
                RCConversationType.ConversationType_SYSTEM.rawValue
            ])
            self.refreshConversationTableViewIfNeeded()
        })
        
    }
    
    // 表格选择事件
    override func onSelectedTableRow(conversationModelType: RCConversationModelType, conversationModel model: RCConversationModel!, atIndexPath indexPath: NSIndexPath!) {
        
        let conversationVC = RCConversationViewController()
        conversationVC.targetId = model.targetId
        conversationVC.userName = model.conversationTitle
        conversationVC.conversationType = RCConversationType.ConversationType_PRIVATE
        conversationVC.title = model.conversationTitle
        
        self.navigationController?.pushViewController(conversationVC, animated: true)
        self.tabBarController?.tabBar.hidden = true
        
    }

    override func viewWillAppear(animated: Bool) {
        
        self.tabBarController?.tabBar.hidden = false
    }
    

    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        
        self.tabBarController?.tabBar.hidden = true
    }

}
